from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
driver.get("http://121.43.169.97:8848/pageA.html")

"""通过Xpath_绝对路径定位"""
# driver.find_element(By.XPATH, "html/body/div/fieldset/form/p[python基础]/input").send_keys("admin")

"""通过Xpath_相对路径定位"""
# driver.find_element(By.XPATH, "//p[python基础]/input").send_keys("admin")

"""
通过Xpath_路径+属性定位
python基础. //标签名[@属性名="属性值"]
2. //*[@属性名="属性值"]
3. //*[@属性名1="属性值" and @属性名2="属性值"]
"""
# driver.find_element(By.XPATH, "//input[@name='userA']").send_keys("admin")
# driver.find_element(By.XPATH, "//*[@id='passwordA']").send_keys("123456")
# driver.find_element(By.XPATH, "//input[@id='telA']").send_keys("13633089805")

"""
通过Xpath_属性和逻辑结合定位
//*[@属性名1="属性值" and @属性名2="属性值"]
"""
# driver.find_element(By.XPATH, "//input[@type='button' and @value='prompt']").click()

"""
通过Xpath_层级和属性结合定位
//标签名[@属性名="属性值"]/标签名[@属性名="属性值"]
"""
# driver.find_element(By.XPATH, "//p[@id='pa']/input[@type='text']").send_keys("admin")
# driver.find_element(By.XPATH, "//p/input[@type='password']").send_keys("123456")

"""
通过Xpath_利用元素文本定位
//*[text()="文本"]
"""
driver.find_element(By.XPATH, "//*[text()='打开百度']").click()

"""
通过Xpath_利用局部属性值定位
//*[contains(@属性名，"局部属性值")]
"""
driver.find_element(By.XPATH, "//*[contains(@placeholder,'用户名')]").send_keys("admin")
